package com.etc.controller;

import com.etc.entity.CommentResult;
import com.etc.service.SearchService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@CrossOrigin
@RestController
public class SearchController {
    @Resource
    private SearchService service;

    //楼栋查找
    @RequestMapping("consumer/building/findAll")
    public CommentResult findAllBuilding(@RequestParam(value = "start", required = false) Integer start,
                                         @RequestParam(value = "size", required = false) Integer size){
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllBuilding(start,size);
    }

    @RequestMapping("consumer/building/findByAnyCondition")
    public CommentResult findBuildingByAnyCondition(@RequestBody Map<String, Object> map){
        return service.findBuildingByAnyCondition(map);
    }

    @RequestMapping("consumer/building/findById/{id}")
    public CommentResult findBuildingById(@PathVariable("id")Integer id)
    {
        return service.findBuildingById(id);
    }

    @RequestMapping("consumer/building/findByPark/{id}")
    public CommentResult findBuildingByPark(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                            @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findBuildingByPark(id,start,size);
    }

    //设备信息查找
    @RequestMapping("consumer/device/findAllDevice")
    public CommentResult findAllDevice(@RequestParam(value = "start", required = false) Integer start,
                                 @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllDevice(start,size);
    }

    @RequestMapping("consumer/device/findByPark/{id}")
    public CommentResult findDeviceByPark(@PathVariable("id")Integer id, @RequestParam(value = "start", required = false) Integer start,
                                    @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findDeviceByPark(id, start, size);
    }

    @RequestMapping("consumer/device/findByBuilding/{id}")
    public CommentResult findDeviceByBuilding(@PathVariable("id")Integer id, @RequestParam(value = "start", required = false) Integer start,
                                        @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findDeviceByBuilding(id, start, size);
    }

    @RequestMapping("consumer/device/findByAnyCondition")
    public CommentResult findDeviceByAnyCondition(@RequestBody Map<String,Object> map, @RequestParam(value = "start", required = false) Integer start,
                                            @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findDeviceByAnyCondition(map, start, size);
    }

    @RequestMapping("consumer/device/findById/{id}")
    public CommentResult findDeviceById(@PathVariable("id")Integer id)
    {
        return service.findDeviceById(id);

    }

    @RequestMapping("consumer/device/findByStatus/{status}")
    public CommentResult findByStatus(@PathVariable("status") Integer status)
    {
        return service.findByStatus(status);
    }
    //住户查找
    @RequestMapping("consumer/household/findAllHousehold")
    public CommentResult findAllHousehold(@RequestParam(value = "start", required = false) Integer start,
                                          @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllHousehold(start,size);
    }

    @RequestMapping("consumer/household/findByAnyCondition")
    public CommentResult findHouseholdByAnyCondition(@RequestBody Map<String, Object> map, @RequestParam(value = "start", required = false) Integer start,
                                                     @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        System.out.println("-------------"+map);
        return service.findHouseholdByAnyCondition(map, start, size);
    }

    @RequestMapping("consumer/household/findById/{id}")
    public CommentResult findHouseholdById(@PathVariable("id")Integer id)

    {
        return service.findHouseholdById(id);
    }


    @RequestMapping("consumer/house/findByRoom/{id}")
    public CommentResult findHouseholdByRoom(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                             @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdByRoom(id, start, size);
    }

    @RequestMapping("consumer/household/findInByTime")
    public CommentResult findHouseholdInByTime(String fromtime,String totime,@RequestParam(value = "start", required = false) Integer start,
                                               @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdInByTime(fromtime,totime,start,size);
    }

    @RequestMapping("consumer/household/findOutByTime")
    public CommentResult findHouseholdOutByTime(String fromtime,String totime,@RequestParam(value = "start", required = false) Integer start,
                                                @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdOutByTime(fromtime,totime,start,size);
    }


    @RequestMapping("consumer/household/findByPark/{id}")
    public CommentResult findHouseholdByPark(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                             @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdByPark(id, start, size);
    }

    @RequestMapping("consumer/household/findByBuilding/{id}")
    public CommentResult findHouseholdByBuilding(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                                 @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdByBuilding(id, start, size);
    }

    @RequestMapping("consumer/household/findByOwner/{id}")
    public CommentResult findHouseholdByOwner(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                              @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findHouseholdByOwner(id, start, size);
    }

    //社区信息栏查找
    @RequestMapping("consumer/infobar/findById/{id}")
    public CommentResult findInfobarById(@PathVariable("id")Integer id)
        {
            return service.findInfobarById(id);
        }

    @RequestMapping("consumer/infobar/findByPark/{id}")
    public CommentResult findInfoByPark(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                        @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findInfoByPark(id, start, size);
    }

    @RequestMapping("consumer/infobar/findAllInfobar")
    public CommentResult findAllInfobar(@RequestParam(value = "start", required = false) Integer start,
                                        @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllInfobar(start, size);
    }

    //业主信息查找
    @RequestMapping("consumer/owner/findAllOwner")
    public CommentResult findAllOwner(@RequestParam(value = "start", required = false) Integer start,
                                      @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllOwner(start,size);
    }

    @RequestMapping("consumer/owner/findById/{id}")
    public CommentResult findOwnerById(@PathVariable("id")Integer id)
    {
        return service.findOwnerById(id);
    }

    @RequestMapping("consumer/owner/findByPark")
    public CommentResult findOwnerByPark(@PathVariable("id")Integer id ,@RequestParam(value = "start", required = false) Integer start,
                                         @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findOwnerByPark(id, start, size);
    }

    @RequestMapping("consumer/owner/findByBuilding")
    public CommentResult findOwnerByBuilding(@PathVariable("id")Integer id ,@RequestParam(value = "start", required = false) Integer start,
                                             @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findOwnerByBuilding(id, start, size);
    }

    @RequestMapping("consumer/owner/findByRoom/{id}")
    public CommentResult findOwnerByRoom(@PathVariable("id")Integer id)
    {
        return service.findOwnerByRoom(id);
    }

    //小区信息查询
    @RequestMapping("consumer/park/findAllPark")
    public CommentResult findAllPark(@RequestParam(value = "start", required = false) Integer start,
                                     @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllPark(start,size);
    }

    @RequestMapping("consumer/park/findByAnyCondition")
    public CommentResult findParkByAnyCondition(@RequestBody Map<String, Object> map,@RequestParam(value = "start", required = false) Integer start,
                                                @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findParkByAnyCondition(map, start, size);
    }

    @RequestMapping("consumer/park/findById/{id}")
    public CommentResult findParkById(@PathVariable("id")Integer id)
    {
        return service.findParkById(id);
    }

    //房间信息查询
    @RequestMapping("consumer/room/findAllRoom")
    public CommentResult findAllRoom(@RequestParam(value = "start", required = false) Integer start,
                                     @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findAllRoom(start, size);
    }

    @RequestMapping("consumer/room/findById/{id}")
    public CommentResult findRoomById(@PathVariable("id") Integer id)
    {
        return service.findRoomById(id);
    }

    @RequestMapping("consumer/room/findByPark/{id}")
    public CommentResult findRoomByPark(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                        @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findRoomByPark(id, start, size);
    }

    @RequestMapping("consumer/room/findByBuilding/{id}")
    public CommentResult findRoomByBuilding(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                            @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findRoomByBuilding(id, start, size);
    }

    @RequestMapping("consumer/room/findByOwner/{id}")
    public CommentResult findRoomByOwner(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                         @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findRoomByOwner(id, start, size);
    }

    @RequestMapping("consumer/room/findByRoomNum/{id}")
    public CommentResult findByRoomNum(@PathVariable("id")Integer id,@RequestParam(value = "start", required = false) Integer start,
                                       @RequestParam(value = "size", required = false) Integer size)
    {
        if (start!=null&&size!=null) {
            start = start <= 0 ? 1 : start;
            size = size <= 0 ? 5 : size;

        }else{
            start=1;
            size=5;
        }
        return service.findByRoomNum(id,start,size);
    }
    @RequestMapping("consumer/room/findFreeRoom")
    public CommentResult findFreeRoom(@RequestParam(value = "start", required = false) Integer start,
                                      @RequestParam(value = "size", required = false) Integer size)
    {
        return service.findFreeRoom(start, size);
    }
    @RequestMapping("consumer/room/findFreeRoomByBuilding/{id}")
    public CommentResult findFreeRoomByBuilding(@PathVariable("id")Integer id)
    {
        return service.findFreeRoomByBuilding(id);
    }

    @RequestMapping("consumer/room/findBusyRoom")
    public CommentResult findBusyRoom(){
       return service.findBusyRoom();
    }

    @RequestMapping("consumer/room/findBusyRoomByBuilding/{id}")
    public CommentResult findBusyRoomByBuilding(@PathVariable("id") Integer id)
    {
        return service.findBusyRoomByBuilding(id);
    }

    //缴费单查询

    //查询逾期缴费信息
    @RequestMapping("conusmer/payment/findAllExceed")
    public CommentResult findAllExceed(){
        return service.findAllExceed();
    }

    @RequestMapping("consumer/payment/findByStatus/{status}")
    public CommentResult findPaymentByStatus(@PathVariable("status") Integer status){
        return service.findPaymentByStatus(status);
    }

    @RequestMapping("consumer/payment/findByRoom/{id}")
    public CommentResult findByRoom(@PathVariable("id") Integer id){
        return service.findPaymentByRoom(id);
    }

    @RequestMapping("consumer/payment/findById/{id}")
    public CommentResult findPaymentById(@PathVariable("id") Integer id){
        return service.findPaymentById(id);
    }

    @RequestMapping("consumer/payment/findAllPayment")
    public CommentResult findAllPayment()
    {
        return service.findAllPayment();
    }

}
